﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TomShane.Neoforce.Controls;
using Microsoft.Xna.Framework;

namespace CaptialVices
{
    public class LevelEditor
    {
        private Manager manager;
        public LevelEditor(Manager manager)
        {
            this.manager = manager;
        }

        public int BlockIndex
        {
            get;
            private set;
        }

        public int BlockHeight
        {
            get;
            set;
        }

        public String BlockType
        {
            get;
            set;
        }

        public Window CreateLevelEditor()
        {
            // Create and setup Window control.
            Window window;
            window = new Window(manager);
            window.Init();
            window.Text = "Level Editor";
            window.Top = 150; // this is in pixels, top-left is the origin
            window.Left = 250;
            window.Width = 350;
            window.Height = 350;

            TomShane.Neoforce.Controls.StackPanel stackPanel = new StackPanel(manager, Orientation.Vertical);
            stackPanel.Init();
            stackPanel.Width = window.Width;
            stackPanel.Height = window.Height;
            stackPanel.Parent = window;

            TomShane.Neoforce.Controls.SpinBox spinBox = new SpinBox(manager, SpinBoxMode.Range);
            spinBox.Init();
            spinBox.Minimum = 100;
            spinBox.Maximum = 1000;
            spinBox.Step = 1;
            spinBox.Width = 200;
            spinBox.Height = 20;
            spinBox.TextColor = Color.White;
            spinBox.Text = "0.0";
            spinBox.TextChanged += new TomShane.Neoforce.Controls.EventHandler(changeBlockHeight);
            stackPanel.Add(spinBox);

            ComboBox blockTypeCombo = new ComboBox(manager);
            blockTypeCombo.Init();
            blockTypeCombo.Top = 20;
            blockTypeCombo.Width = 200;
            blockTypeCombo.Height = 20;
            blockTypeCombo.TextColor = Color.White;
            foreach (String blockTypeString in Blocks.GetBlocks())
            {
                blockTypeCombo.Items.Add(blockTypeString);
            }
            blockTypeCombo.TextChanged += new TomShane.Neoforce.Controls.EventHandler(changeBlockType);

            stackPanel.Add(blockTypeCombo);


            // Add the window control to the manager processing queue.
            manager.Add(window);

            return window;
        }

        void changeBlockType(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            this.BlockType = (sender as ComboBox).Text;
        }

        void changeBlockHeight(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            this.BlockHeight = (int)float.Parse((sender as SpinBox).Text);
        }
    }
}
